package com.zgis.monitor.service;

import com.zgis.monitor.config.MonitorConfig;
import com.zgis.monitor.model.ServiceStatus;
import com.zgis.monitor.model.dto.ServiceListDTO;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 服务监控接口
 */
@Component
public interface MonitorService
{

    /**
     * 检查服务状态
     */
    ServiceStatus checkStatus(MonitorConfig.ServerConfig server, MonitorConfig.ServiceConfig service);

    /**
     * 启动服务
     */
    boolean startService(MonitorConfig.ServerConfig server, MonitorConfig.ServiceConfig service);

    /**
     * 停止服务
     */
    boolean stopService(MonitorConfig.ServerConfig server, MonitorConfig.ServiceConfig service);

    /**
     * 重启服务
     */
    default boolean restartService(MonitorConfig.ServerConfig server, MonitorConfig.ServiceConfig service)
    {
        stopService(server, service);
        try
        {
            Thread.sleep(1000);
        }
        catch (InterruptedException e)
        {
            Thread.currentThread().interrupt();
        }
        return startService(server, service);
    }

    /**
     * 获取所有服务状态
     */
    List<ServiceStatus> getAllServiceStatus();

    /**
     * 获取所有服务列表，包含基本信息和状态
     *
     * @return
     */
    List<ServiceListDTO> getServiceListWithStatus();
}
    